/**
 * 
 */
package org.lavemylogic.friendsfinder.controller;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.lavemylogic.friendsfinder.MainActivity;
import org.lavemylogic.friendsfinder.utilities.CustomIndicator;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.model.GraphUser;

/**
 * @author Paner
 *
 */
public class CustomRequest {

	public static void getFriends(final MainActivity activity) {
		CustomIndicator.show(activity, "Please wait!", "Getting facebook friends..");
		Request request = Request.newMyFriendsRequest(
            	Session.getActiveSession(),
            	new Request.GraphUserListCallback() {
            		 @Override
            		 public void onCompleted(List<GraphUser> users, Response response) {
            			 activity.setFriends(users);
            			 
            			 List<GraphUser> userList = new ArrayList<GraphUser>(users);
            			 userList.add(0, activity.getUser());

            	
            			 CustomIndicator.close();
            			 activity.showMapActivity();
            		 }
            	});
            	request.executeAsync();
	}
	
	public static void setProfilePicForFriend(final MainActivity activity, GraphUser user) throws MalformedURLException {
		URL image_value = new URL("http://graph.facebook.com/" + user.getId() + "/picture?style=small");
		user.setProperty("profilePic", image_value);
	}
	
}
